package _26define;

public class EX {
    private static String arr="1A2B3C4D5E6F7G";
    public static final Object OBJECT = new Object();
    public static void main(String[] args) {
        new Thread(()->{
            synchronized (OBJECT) {
                for (int i = 0; i < arr.length(); i+=2) {
                    OBJECT.notify();
                    System.out.println(Thread.currentThread().getName()+
                            "----"+arr.charAt(i));
                    try {
                        OBJECT.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                OBJECT.notify();
            }
        },"A").start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
            synchronized (OBJECT) {
                for (int i = 1; i < arr.length(); i+=2) {
                    OBJECT.notify();
                    System.out.println(Thread.currentThread().getName()+
                            "----"+arr.charAt(i));
                    try {
                        OBJECT.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                OBJECT.notify();

            }
        },"B").start();
    }
}